const { axios } = require('../../utils/http')
import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify.js'

Page({
  data: {
    realname: ''
  },
  changeRealname() {
    if (this.data.realname.trim() === '') {
      Notify({
        message: '请输入新昵称'
      })
      return
    }
    const userInfo = wx.getStorageSync('userInfo')
    axios
      .post('/user/updateRealname', {
        realname: this.data.realname,
        id: userInfo.id
      })
      .then(res => {
        console.log(res)
        if (res.data.error === -1) {
          wx.setStorageSync('userInfo', {
            ...userInfo,
            realname: this.data.realname
          })
          wx.navigateBack()
        }
      })
  }
})
